<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>

<body>

	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="mgcmz-table" lay-filter="mgcmz-table"></table>
			</div>
		</div>
	</body>

	<script type="text/html" id="mgcmz-toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="clean">
		        清空
		    </button>
		</script>

	<script type="text/html" id="mgcmz-bar">
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">删除</button>
	</script>
	<script type="text/html" id="type-tpl">
		{{d.type==0?"单聊":"群聊"}}
	</script>
	<script type="text/html" id="createTime-tpl">
		{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}
	</script>
	<script type="text/html" id="id">
		{{d.LAY_TABLE_INDEX+1}}
	</script>
	<script src="../../component/layui/layui.js"></script>
	<script src="../../component/pear/pear.js"></script>
	<script>
		layui.use(['table', 'form', 'jquery'], function () {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;


			let cols = [
				[
					{
						title: '序号',
						field: 'id',
						align: 'center',
						width: 100,
						templet: "#id"
					},
					{
						title: '发送者ID',
						field: 'sender',
						align: 'center'
					},
					{
						title: '接收者ID',
						field: 'target',
						align: 'center'
					},
					{
						title: '接收者',
						field: 'recipient',
						align: 'center'
					},
					{
						title: '消息内容',
						field: 'content',
						align: 'center'
					},
					{
						title: '类型',
						field: 'type',
						align: 'center',
						templet:"#type-tpl"
					}
			,
			{
				title: '时间',
				field: 'createTime',
				align: 'center',
				templet: "#createTime-tpl"
			},
			{
				title: '操作',
				toolbar: '#mgcmz-bar',
				align: 'center',
				width: 130
			}
				]
			]

			table.render({
				elem: '#mgcmz-table',
				url: '/api/sensitive/message/list',
				page: true,
				cols: cols,
				skin: 'line',
				toolbar: '#mgcmz-toolbar',
				defaultToolbar: [{
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});

		table.on('tool(mgcmz-table)', function (obj) {
			if (obj.event === 'remove') {
				window.remove(obj);
			} else if (obj.event === 'edit') {
				window.edit(obj);
			} else if (obj.event == "clean") {
				window.clean();
			}
		});

		table.on('toolbar(mgcmz-table)', function (obj) {
			if (obj.event === 'clean') {
				window.clean();
			} else if (obj.event === 'refresh') {
				window.refresh();
			}
		});

		form.on('submit(mgcmz-query)', function (data) {
			table.reload('mgcmz-table', {
				where: data.field
			})
			return false;
		});

		form.on('switch(mgcmz-enable)', function (obj) {
			layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
		});

		window.clean = function () {
			layer.msg("清空");
		}

		window.edit = function (obj) {
			layer.msg("修改");
		}

		window.remove = function (obj) {
			layer.confirm('确定要删除吗？', {
				icon: 3,
				title: '提示'
			}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: '/api/sensitive/message/remove/' + obj.data.id,
					dataType: 'json',
					success: function (result) {
						layer.close(loading);
						if (result.msg == "删除成功") {
							layer.msg(result.msg, {
								icon: 1,
								time: 1000
							}, function () {
								table.reload('mgcmz-table');
							});
						} else {
							layer.msg(result.msg, {
								icon: 2,
								time: 1000
							});
						}
					}
				})
			});
		}
		//清空
		window.clean = function () {
			layer.confirm('确定要清空所有吗？', {
				icon: 3,
				title: '提示'
			}, function (index) {
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url: '/api/sensitive/message/clean',
					dataType: 'json',
					success: function (result) {
						layer.close(loading);
						if (result.msg == "清空成功") {
							layer.msg(result.msg, {
								icon: 1,
								time: 1000
							}, function () {
								table.reload('mgcmz-table');
							});
						} else {
							layer.msg(result.msg, {
								icon: 2,
								time: 1000
							});
						}
					}
				})
			});
		}

		window.refresh = function (param) {
			table.reload('mgcmz-table');
		}
		})
	</script>
</body>

</html>
